//
//  ViewController.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/3/16.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "ViewController.h"
#import "openOrCloseModel.h"
#import "BaseCell.h"
#import "CloseCell.h"
#import "OpenCell.h"
//#import "ADverWebViewController.h"
#import "GGScrollViewController.h"
#import "GGResetlaytouViewController.h"
#import "GGTableViewController.h"
#import "GGlifeViewController.h"
#import "GGCollectionViewController.h"
//#import "NSArray+URLAddtion.h"
#import "GGAddtion.h"
#import "GGScrollViewAndCollectionViewController.h"
#import "GDCycleViewController.h"
#import "ScrollViewAddTableViewController.h"
#import "SemaphoreViewController.h"
#import "GDAdvertiseViewController.h"
#import "GDWebAdvertiseViewController.h"
#import "stackViewViewController.h"
#import "GCDViewController.h"
#import "iconChangeViewController.h"
#import "GAButtonViewController.h"
#import "SIViewController.h"
#import "viewtableViewHeaderView.h"
#import "GDSqliteDataViewController.h"
#import "GDdataModel.h"
#import "GDImageViewController.h"
#import "GDFMDBViewController.h"
#import "RACViewController.h"

//clang 静态插桩所使用的头文件
#import <dlfcn.h>
#import <libkern/OSAtomic.h>

//原子队列
static OSQueueHead symboList = OS_ATOMIC_QUEUE_INIT;
//定义符号结构体
typedef struct{
    void * pc;
    void * next;
}SymbolNode;



//static NSString *cellID = @"cellID";
@interface ViewController () <UITableViewDelegate,UITableViewDataSource,BaseCellDelegate,headerViewDelegate,UIViewControllerPreviewingDelegate,UIContextMenuInteractionDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray <NSDictionary *>*listArray;
@property (nonatomic, strong) NSMutableArray <openOrCloseModel *>*dataArray;

//标记cell的状态
@property (nonatomic, assign) NSInteger isOpen;
//标记是哪一行cell
@property (nonatomic, assign) NSInteger cellIndex;
//保存每行cell的状态
@property (nonatomic, strong) NSMutableArray *statusArray;
//背景图片
@property (nonatomic, strong) UIImageView *backImage;

@property (nonatomic, strong) GDAdvertiseViewController *gdText;

@property (nonatomic, strong) NSMutableArray <openOrCloseModel *>*modelDataArray;


@property (nonatomic, strong) GDImageViewController *imageViewVC;
@end


@implementation ViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    //t导航栏透明
//     [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//     [self.navigationController.navigationBar setShadowImage:[UIImage new]];
//    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"DJ_Apple";
    self.view.backgroundColor = [UIColor whiteColor];
    //
    UIView *thisView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, GDScreenW, 0)];
    [self.view addSubview:thisView];
    
    [self loadData];
    
//    UIImage *img = [UIImage imageNamed:@"newbackImage"];
//    self.view.layer.contents = (id)img.CGImage;//推荐
    
    [self.view addSubview:self.tableView];

    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, GDScreenW, GDScreenW)];
    headerView.backgroundColor = [UIColor clearColor];
    viewtableViewHeaderView *backView = [[viewtableViewHeaderView alloc]initWithFrame:CGRectMake(0, 0, GDScreenW, GDScreenW)];
    [headerView addSubview:backView];
    backView.delegate = self;
    self.tableView.tableHeaderView = headerView;
    
    
//    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    //获取当前横竖屏
    if ([UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationLandscapeRight ||
    [UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationLandscapeLeft) {
        //当前横屏
        NSLog(@"横屏");
    } else {
       //当前竖屏
        NSLog(@"竖屏");
    }
    
    
    //注册通知 弹出广告页
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jumpToAdVC) name:@"pushtoad" object:nil];
    
    //延时
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //网页加载完了，置空进度条
        //clang静态插桩
//        [self sayHello];
    });
    
//    [[self rac_signalForSelector:@selector()] subscribeNext:^(RACTuple * _Nullable x) {
//            
//    }];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
}
#pragma mark - 加载数据
- (void)loadData{
//    self.dataArray = [NSArray gg_arrayModelWithPlistName:@"dataList.plist" withClassName:@"openOrCloseModel"].mutableCopy;
    
    //开始使用 数据库
    [GDDataBase creatSqliteWithSqliteName:SqliteName];
    [GDDataBase creatTableName:tableName withTableStatusBlock:^(BOOL status) {
        if(status == YES){
            NSLog(@"已经创建该表！");
            //创建了表成功之后，搜索表中所有的数据用于展示
            [self selectDataFromSqliteWithTableName:tableName];
        }else{
            //系统第一次进入并没有
            NSLog(@"没有创建该表！");
        }
    }];
}
#pragma mark -查询数据库中所有数据（用于数据源）
- (void)selectDataFromSqliteWithTableName:(NSString *)tableName{
    [GDDataBase selectSqliteAllModelWithTable:tableName success:^(NSArray * _Nonnull array) {
        [self.dataArray removeAllObjects];
        if(array.count == 0){
            /**
             没有数据，数据已经删除完了
             */
//            [self addDataToSqliteWithTableName:tableName];
        }else{
            for (NSDictionary *dic in array) {
                //根据名称实例化对象
                openOrCloseModel *model = [[openOrCloseModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [self.dataArray addObject:model];
            }
            [self.tableView reloadData];
        }
    } fail:^(BOOL fail) {
        NSLog(@"没有任何数据！！");
    }];
}
#pragma mark - 查询数据库中所有数据（用于展示）
- (void)selectAllDataFromSqliteWithTableName:(NSString *)tableName{
    [GDDataBase selectSqliteAllModelWithTable:tableName success:^(NSArray * _Nonnull array) {
        [self.dataArray removeAllObjects];
        if(array.count == 0){
            [self showAlertControllerWithInformation:@"没有任何数据"];
        }else{
            for (NSDictionary *dic in array) {
                //根据名称实例化对象
                openOrCloseModel *model = [[openOrCloseModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [self.dataArray addObject:model];
            }
        }
    } fail:^(BOOL fail) {
        NSLog(@"没有任何数据！！");
    }];
}
#pragma mark - 查询单条数据
- (void)selectSqliteWithTableName:(NSString *)tableName withID:(NSString *)ID{
    [GDDataBase selectSqliteWithTableName:tableName withSqliteID:ID success:^(NSDictionary * _Nonnull dic) {
        [self.dataArray removeAllObjects];
        openOrCloseModel *model = [[openOrCloseModel alloc]initGroupWithDict:dic];
        [self.dataArray addObject:model];
    } fail:^(BOOL status) {
        [self showAlertControllerWithInformation:@"搜索无结果！"];
    }];
}
#pragma mark - 查询多条数据
- (void)selectArraySqliteWithTableName:(NSString *)tableName withArray:(NSArray *)array{
    [GDDataBase selectArraySqliteWithTableName:tableName withSqliteArray:array success:^(NSArray * _Nonnull array, NSArray * _Nonnull notSelectArray) {
        [self.dataArray removeAllObjects];
        for (NSDictionary *dic in array) {
            openOrCloseModel *model = [[openOrCloseModel alloc]initGroupWithDict:dic];
            [self.dataArray addObject:model];
        }
        if(notSelectArray.count == 0){
            
        }else{
            NSString *string = @"";
            for (NSString *str in notSelectArray) {
                string = [string stringByAppendingString:[NSString stringWithFormat:@"%@",str]];
            }
            [self showAlertControllerWithInformation:[NSString stringWithFormat:@"%@",string]];
        }
    } fail:^(BOOL status) {
        [self showAlertControllerWithInformation:@"查询失败！"];
    }];
}
#pragma mark - 添加单条数据
- (void)addSqliteWithID:(NSString *)ID withName:(NSString *)tipStr withDescName:(NSString *)descStr withTableName:(NSString *)tableName{
    [GDDataBase addSqliteID:ID withName:tipStr withdescName:descStr withTableName:tableName success:^(BOOL status) {
        NSLog(@"添加数据成功");
        [self showAlertControllerWithInformation:@"数据添加成功"];
        [self selectDataFromSqliteWithTableName:tableName];
    } fail:^(BOOL status) {
        NSLog(@"添加数据失败");
        [self showAlertControllerWithInformation:@"添加数据失败"];
    }];
}
#pragma mark - 添加多条数据到数据库
- (void)addDataToSqliteWithTableName:(NSString *)tableName withDataArray:(NSArray *)dataArray{
    
    [GDDataBase addSqliteTableName:tableName modelArray:dataArray failArray:^(NSArray * _Nonnull failArray) {
        if(failArray.count == 0){
            NSLog(@"插入数据成功！");
            [self showAlertControllerWithInformation:@"插入数据成功！"];
            [self selectDataFromSqliteWithTableName:tableName];
        }else{
            NSLog(@"插入数据失败！");
            [self showAlertControllerWithInformation:@"插入数据失败！"];
        }
    }];
}
#pragma mark - 删除一条数据
- (void)deleteSqliteDataWithTableName:(NSString *)tableName withSqliteID:(NSString *)ID{
    [GDDataBase deleteSqliteWithTableName:tableName withSqliteID:ID success:^(BOOL status) {
        [self showAlertControllerWithInformation:[NSString stringWithFormat:@"删除%@数据成功!",ID]];
        [self selectAllDataFromSqliteWithTableName:tableName];
    } fail:^(BOOL status) {
        [self showAlertControllerWithInformation:@"删除数据失败！"];
    }];
}
#pragma mark - 删除多条数据
- (void)deleteSqliteArrayWithTableName:(NSString *)tableName withSqliteArray:(NSArray *)array{
    [GDDataBase deletaSqliteArrayWithTableName:tableName withSqliteArray:array success:^(BOOL status) {
        if(status == YES){
            [self showAlertControllerWithInformation:@"删除数据成功！"];
            [self selectAllDataFromSqliteWithTableName:tableName];
        }else{
            [self showAlertControllerWithInformation:@"删除数据失败！"];
        }
    } fail:^(NSArray * _Nonnull failArray) {
        
    }];
}
#pragma mark - 删除所有数据
- (void)deleteAllDataSqliteWithTableName:(NSString *)tableName{
    [GDDataBase deleteSqliteAllDataWithTableName:tableName success:^(BOOL status) {
        [self showAlertControllerWithInformation:@"已删除所有数据！"];
        [self selectAllDataFromSqliteWithTableName:tableName];
    } fail:^(NSArray * _Nonnull array) {
        NSLog(@"删除所有数据失败！");
    }];
}
#pragma mark - 修改数据库中单条数据
- (void)updataSqliteDataWithTableName:(NSString *)tableName withID:(NSString *)ID withDescStr:(NSString *)descStr withTipStr:(NSString *)tipStr{
    [GDDataBase updataSqliteWithTableName:tableName withID:ID withTipStr:tipStr withDescStr:descStr success:^(BOOL status) {
        [self showAlertControllerWithInformation:@"修改成功！"];
        [self selectAllDataFromSqliteWithTableName:tableName];
    } fail:^(BOOL fail) {
        [self showAlertControllerWithInformation:@"修改失败！"];
    }];
}
#pragma mark - 修改数据中多条数据
- (void)updateSqliteDataWithTableName:(NSString *)tableName withArray:(NSArray *)array{
    [GDDataBase updateSqlieWithTableName:tableName withArray:array success:^(BOOL status) {
        [self showAlertControllerWithInformation:@"修改多条数据成功！"];
        [self selectAllDataFromSqliteWithTableName:tableName];
    } fail:^(NSArray * _Nonnull failArray) {
        [self showAlertControllerWithInformation:@"修改多条数据失败！"];
    }];
}
#pragma mark - 删除表
- (void)dropSqliteTable{
    //因为表的键创建错了，导致数据插不进去
    [GDDataBase dropTableWithTableName:@"skillList" withTableStatus:^(BOOL status) {
        if(status){
            NSLog(@"表删除成功");
        }else{
            NSLog(@"表删除失败");
        }
    }];
}
#pragma mark -viewtableViewHeaderView的代理方法
- (void)selectWithIndexPath:(NSInteger)indexPath{
    
    GDSqliteDataViewController *sqliteDataView = [[GDSqliteDataViewController alloc]init];
    sqliteDataView.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    switch (indexPath) {
        case 0:{
            /**
             创建数据库
             */
            [self showAlertControllerWithInformation:@"已经创建了数据库！"];
            break;
        }
        case 1:{
            /**
             创建表
             */
            [self showAlertControllerWithInformation:@"已经创建了表！"];
            break;
        }
        case 2:{
            //插入单条数据
            /**
             注意插入单条数据时，不能插入重复的数据，如果重复会出错
             */
            [self addSqliteWithID:@"14" withName:@"FMDB二次封装" withDescName:@"FMDB二次封装，直接插入model" withTableName:tableName];
            break;
        }
        case 3:{
            /**
             插入多条数据
             */
            self.modelDataArray = [NSArray gg_arrayModelWithPlistName:@"dataList.plist" withClassName:@"openOrCloseModel"].mutableCopy;
            NSMutableArray * array = [NSMutableArray new];
            for (int i = 0; i < self.modelDataArray.count; i++) {
                openOrCloseModel *model = self.modelDataArray[i];
                NSString * ID = model.ID;
                NSString * descStr = model.descStr;
                NSString * tipStr = model.tipStr;
                NSMutableDictionary * dic = [@{} mutableCopy];
                [dic setValue:ID forKey:@"ID"];
                [dic setValue:descStr forKey:@"descStr"];
                [dic setValue:tipStr forKey:@"tipStr"];
                [array addObject:dic];
            }
            [self addDataToSqliteWithTableName:tableName withDataArray:array];
            break;
        }
        case 4:{
            /**
             查询单条数据
             */
            [self selectSqliteWithTableName:tableName withID:@"3"];
            sqliteDataView.dataArray = self.dataArray;
            [self presentViewController:sqliteDataView animated:NO completion:^{
                
            }];
            break;
        }
        case 5:{
            /**
             查询多条数据
             */
            NSArray *array = @[@"1",@"4",@"2",@"8",@"5",@"7"];
            [self selectArraySqliteWithTableName:tableName withArray:array];
            sqliteDataView.dataArray = self.dataArray;
            [self presentViewController:sqliteDataView animated:NO completion:^{
                
            }];
            break;
        }
        case 6:{
            /**
             查询所有数据
             */
            [self selectAllDataFromSqliteWithTableName:tableName];
            sqliteDataView.dataArray = self.dataArray;
            [self presentViewController:sqliteDataView animated:NO completion:^{
                
            }];
            break;
        }
        case 7:{
            /**
             删除单条数据
             */
            [self deleteSqliteDataWithTableName:tableName withSqliteID:@"102"];
            sqliteDataView.dataArray = self.dataArray;
            [self presentViewController:sqliteDataView animated:NO completion:^{
                
            }];
            break;
        }
        case 8:{
            /**
             删除多条数据
             */
            NSArray *array = @[@"10",@"11"];
            [self deleteSqliteArrayWithTableName:tableName withSqliteArray:array];
            
            sqliteDataView.dataArray = self.dataArray;
            [self presentViewController:sqliteDataView animated:NO completion:^{
                
            }];
            break;
        }
        case 9:{
            /**
             删除所有的数据
             */
            [self deleteAllDataSqliteWithTableName:tableName];
            break;
        }
        case 10:{
            [self updataSqliteDataWithTableName:tableName withID:@"0" withDescStr:@"天青色等烟雨" withTipStr:@"青花瓷"];
            break;
        }
        case 11:{
            NSArray * updateArray = @[
              @{@"ID": @"1", @"tipStr": @"hello", @"descStr": @"修改的第一条数据"},
              @{@"ID": @"3", @"tipStr": @"hi", @"descStr": @"我想修改的数据"},
              @{@"ID": @"5", @"tipStr": @"nihao", @"descStr": @"这就是修改的数据"}
              ];
            [self updateSqliteDataWithTableName:tableName withArray:updateArray];
            break;
        }
        default:
            break;
    }
    [self.tableView reloadData];
}

- (void)showImaViewIfClick{
    self.imageViewVC = [[GDImageViewController alloc]init];
    //modal时需要设置弹出的模式
    self.imageViewVC.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:self.imageViewVC animated:NO completion:nil];
}

#pragma mark - delegate datasource
/**
设置组头时需要同时组头的高度和视图
 */
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return GGTableViewHeaderH;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, GDScreenW, GGTableViewHeaderH)];
    headerV.backgroundColor = [UIColor clearColor];
    
    UIView *showView = [[UIView alloc]initWithFrame:CGRectZero];
    showView.backgroundColor = NormalColor;
    showView.layer.cornerRadius = 10.0f;
    showView.layer.masksToBounds = YES;
    [headerV addSubview:showView];
    [showView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(headerV);
        make.width.mas_equalTo(GDScreenW - 30);
        make.height.mas_equalTo(GGTableViewHeaderH - 30);
    }];
    return headerV;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    BaseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    BaseCell *cell = nil;
    NSString *cellID;
    
    cell.userInteractionEnabled = NO;//取消互动
    //判断是否被打开 open -> 1 ,close -> 0
    NSString *row = [NSString stringWithFormat:@"%ld",indexPath.row];
    
    //查看是否包括打开的cell
    BOOL isbool = [self.statusArray containsObject:row];
    if(isbool == NO){
        cellID = @"unOpen";
    }else{
        cellID = @"open";
    }
    //因为存在有两种不同的cell 
    cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        if(isbool == NO){
            cell = [[CloseCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }else{
            cell = [[OpenCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
    }else{
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    //判断是否支持3D touch
//    if(self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable){
//        //支持3D touch
//        NSLog(@"支持3D touch");
//        //IOS13已经废弃了
////        [self registerForPreviewingWithDelegate:self sourceView:cell];
//        //UIMenus
//        //给cell添加一个上下文菜单交互
//        UIContextMenuInteraction *interaction = [[UIContextMenuInteraction alloc]initWithDelegate:self];
//        [cell addInteraction:interaction];
//
//    }else{
//        //不支持3D touch
//        NSLog(@"不支持3D touch");
//    }
    cell.backgroundColor =  [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataArray[indexPath.row];
//    [cell setView:cell.model];
    cell.delegate = self;
    //将当前所在的行与状态数组传递给cell
    cell.index = (int)indexPath.row;
    cell.indexArr = self.statusArray;
    return cell;
}
#pragma mark - 设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *row = [NSString stringWithFormat:@"%ld",indexPath.row];
    BOOL isbool = [self.statusArray containsObject:row];
    
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    
    if(isbool == NO){
        return 136;  //关闭状态时行高
    }else{
        return cell.frame.size.height + 22;  //打开状态时行高中间可以有行间距
    }
    return indexPath.row;
}
#pragma mark - cell代理方法
- (void)baseCell:(BaseCell *)baseCell withBtnType:(BtnType)btnType withIndex:(int)index withArray:(NSMutableArray *)array{
    
    self.isOpen = btnType;
    self.cellIndex = index;
    
    self.statusArray = array;//
    
    //获取点击的行数 并更新指定的行数
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
    
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark - 点击cell进行跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            GGScrollViewController *ggSrollView = [[GGScrollViewController alloc]init];
            [self.navigationController pushViewController:ggSrollView animated:YES];
             break;
        }
           
        case 1:{
            GGResetlaytouViewController *ggResetVC = [[GGResetlaytouViewController alloc]init];
            [self.navigationController pushViewController:ggResetVC animated:YES];
            break;
        }
        case 2:{
            GGTableViewController *ggTableView = [[GGTableViewController alloc]init];
            [self.navigationController pushViewController:ggTableView animated:YES];
            break;
        }
        case 3:{
            GGlifeViewController *lifeVC = [[GGlifeViewController alloc]init];
            [self.navigationController pushViewController:lifeVC animated:YES];
            break;
        }
        case 4:{
            GGCollectionViewController  *ggCollectionViewVVC = [[GGCollectionViewController alloc]init];
            [self.navigationController pushViewController:ggCollectionViewVVC animated:YES];
            break;
        }
        case 5:{
            GGScrollViewAndCollectionViewController *scroAndCollecVC = [[GGScrollViewAndCollectionViewController alloc]init];
            [self.navigationController pushViewController:scroAndCollecVC animated:YES];
            break;
        }
        case 6:{
            GDCycleViewController *cycleVC = [[GDCycleViewController alloc]init];
            [self.navigationController pushViewController:cycleVC animated:YES];
        }
            break;
        case 7:{
            ScrollViewAddTableViewController *scrollAddTableViewVC = [[ScrollViewAddTableViewController alloc]init];
            [self.navigationController pushViewController:scrollAddTableViewVC animated:YES];
            break;
        }
        case 8:{
            SemaphoreViewController *semaphoreVC = [[SemaphoreViewController alloc]init];
            [self.navigationController pushViewController:semaphoreVC animated:YES];
            break;
        }
        case 9:{
            stackViewViewController *stackVC = [[stackViewViewController alloc]init];
            [self.navigationController pushViewController:stackVC animated:YES];
            break;
        }
        case 10:{
            GCDViewController *GCDVC = [[GCDViewController alloc]init];
            [self.navigationController pushViewController:GCDVC animated:YES];
            break;
        }
        case 11:{
            iconChangeViewController *iconVC = [[iconChangeViewController alloc]init];
            [self.navigationController pushViewController:iconVC animated:YES];
            
            break;
        }
        case 12:{
            GAButtonViewController *btnVC = [[GAButtonViewController alloc]init];
            //clickButtonWithIndex:如果是需要使用RAC代替代理方法的话，需要先在头文件中声明一下，不然找不到
            @weakify(self);
            [[btnVC rac_signalForSelector:@selector(clickButtonWithIndex:)] subscribeNext:^(RACTuple * _Nullable x) {
                //刷新单行cell
                NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
                [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:index, nil] withRowAnimation:UITableViewRowAnimationNone];
            }];
            
            [self.navigationController pushViewController:btnVC animated:YES];
            break;
        }
        case 13:{
            //静态内联函数
            SIViewController *siVC = [[SIViewController alloc]init];
            [self.navigationController pushViewController:siVC animated:YES];
            break;
        }
        case 14:{
            //
            GDFMDBViewController *fmdbVC = [[GDFMDBViewController alloc]init];
            [self.navigationController pushViewController:fmdbVC animated:YES];
            break;
        }
        case 15:{
            RACViewController *racVC = [[RACViewController alloc]init];
            [self.navigationController pushViewController:racVC animated:nil];
            break;
        }
        default:
            break;
    }
}

- (void)pushGDWebView{
    NSLog(@"HH-------------");
}
#pragma mark - 弹出提示框
- (void)showAlertControllerWithInformation:(NSString *)information{
    UIAlertController * alter = [UIAlertController alertControllerWithTitle:information message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction * cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alter addAction:sure];
    [alter addAction:cancle];
    [self presentViewController:alter animated:YES completion:nil];
}

#pragma mark - 跳转到广告页
- (void)jumpToAdVC{
    GDWebAdvertiseViewController *webVC = [[GDWebAdvertiseViewController alloc]init];
    webVC.urlStr = @"http://www.jianshu.com/users/e39da354ce50/latest_articles";
    [self.navigationController pushViewController:webVC animated:YES];
}

#pragma mark - lazy
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, GDScreenW, GDScreenH) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource =self;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        
    }
    return _tableView;
}
- (NSMutableArray <openOrCloseModel *>*)modelDataArray{
    if(!_modelDataArray){
        _modelDataArray = [[NSMutableArray alloc]init];
    }
    return _modelDataArray;
}
- (NSMutableArray *)dataArray{
    if(!_dataArray){
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (NSMutableArray <NSDictionary *>*)listArray{
    if(!_listArray){
        _listArray = [NSMutableArray array];
    }
    return _listArray;
}
#pragma mark - 注意，此处需要先将状态数组初始化，不然会如法添加状态
- (NSMutableArray *)statusArray{
    if(!_statusArray){
        _statusArray = [NSMutableArray array];
    }
    return _statusArray;
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
//重写class方法
//- (Class)class{
//    return object_getClass(self);
//}
//重写父类的class方法
//- (Class)class{
//    return class_getSuperclass(object_getClass(self));
//}

#pragma mark - clang 静态插桩
void __sanitizer_cov_trace_pc_guard_init(uint32_t *start,
                                         uint32_t *stop) {
    static uint64_t N;  // Counter for the guards.
    if (start == stop || *start) return;  // Initialize only once.
    printf("INIT: %p %p\n", start, stop);
    for (uint32_t *x = start; x < stop; x++)
        *x = ++N;  // Guards should start from 1.
}
#pragma mark - 静态插桩方法具体实现
- (void)sayHello{
    NSMutableArray<NSString *> * symbolNames = [NSMutableArray array];
    NSLog(@"#################################");
    while (true) {
        //offsetof 就是针对某个结构体找到某个属性相对这个结构体的偏移量
        SymbolNode * node = OSAtomicDequeue(&symboList, offsetof(SymbolNode, next));
        if (node == NULL) break;
        Dl_info info;
        dladdr(node->pc, &info);

        NSString * name = @(info.dli_sname);

        // 添加 _
        BOOL isObjc = [name hasPrefix:@"+["] || [name hasPrefix:@"-["];
        NSString * symbolName = isObjc ? name : [@"_" stringByAppendingString:name];

        //去重
        if (![symbolNames containsObject:symbolName]) {
            [symbolNames addObject:symbolName];
        }
    }
    //取反
    NSArray * symbolAry = [[symbolNames reverseObjectEnumerator] allObjects];
    NSLog(@"%@",symbolAry);

    //将结果写入到tmp文件路径下
    NSString * funcString = [symbolAry componentsJoinedByString:@"\n"];
    NSString * filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"gunter.order"];
    NSData * fileContents = [funcString dataUsingEncoding:NSUTF8StringEncoding];
    BOOL result = [[NSFileManager defaultManager] createFileAtPath:filePath contents:fileContents attributes:nil];
    if (result) {
        NSLog(@"%@",filePath);
    }else{
        NSLog(@"文件写入出错");
    }
    NSLog(@"#################################");
}

void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {
    //if (!*guard) return;  // Duplicate the guard check.

    void *PC = __builtin_return_address(0);

    SymbolNode * node = malloc(sizeof(SymbolNode));
    *node = (SymbolNode){PC,NULL};

    //入队
    // offsetof 用在这里是为了入队添加下一个节点找到 前一个节点next指针的位置
    OSAtomicEnqueue(&symboList, node, offsetof(SymbolNode, next));
}



@end
